package com.bizihang.common.security.server;

import com.bizihang.common.security.app.authentication.AppAuthenticationFailureHandler;
import com.bizihang.common.security.app.authentication.AppAuthenticationSuccessHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
 * 基本的安全配置
 *
 * @author 毕子航 951755883@qq.com
 * @date 2018/11/15
 */
@Configuration
public class SecurityAutoConfiguration {
	/**
	 * 认证成功的处理逻辑
	 *
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean(value = {AuthenticationFailureHandler.class})
	public AuthenticationFailureHandler authenticationFailureHandler() {
		return new AppAuthenticationFailureHandler();
	}

	/**
	 * 认证失败的默认处理逻辑
	 *
	 * @return
	 */
	@Bean
	@ConditionalOnMissingBean(value = {AuthenticationSuccessHandler.class})
	public AuthenticationSuccessHandler authenticationSuccessHandler() {
		return new AppAuthenticationSuccessHandler();
	}
}